<template>
  <div>
    <button @click="ishow = true">点我他个床</button>
    <teleport to="body">
      <!-- 将这些内容传送到指定的位置 -->
      <div v-show="ishow" class="mask">
        <div class="dialog">
          <h3>我是一个弹窗</h3>
          <h4>内容</h4>
          <button @click="ishow = false">关闭弹窗</button>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  name: "Dialog",
  setup() {
    let ishow = ref(false);
    //为什么f1无效呢
    /*  function f1(){
        ishow=true
    } */
    return {
      ishow,
    };
  },
};
</script>

<style>
.dialog {
  text-align: center;
  position: absolute;
  top: 50%;
  left: 50%;  /* 参考定位 */
  transform:translate(-50%,-50%);  /* 参考自身 */
  width: 300px;
  height: 300px;
  background-color: green;
}
/* 遮罩层的样式 */
.mask {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);
}
</style>